package com.yinhai.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.androidquery.AQuery;
import com.yinhai.activity.R;
import com.yinhai.model.NewsContent;

public class NewsContentListAdapter extends BaseAdapter {
	private ArrayList<NewsContent> dataList;
	private LayoutInflater layoutInflater;
	private Context context;
	
	public NewsContentListAdapter(Context context){
		this.context=context;
		this.dataList=new ArrayList<NewsContent>();
		this.layoutInflater=LayoutInflater.from(this.context);
	}
	
	public void addItem(NewsContent item){
		dataList.add(item);
	}
	
	public void clear(){
		dataList.clear();
	}
	
	@Override
	public int getCount() {
		return dataList.size();
	}

	@Override
	public NewsContent getItem(int position) {
		return dataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView==null) {
			convertView = layoutInflater.inflate(R.layout.item_main_news, null);
		}
		AQuery aq = new AQuery(convertView);
		NewsContent u = getItem(position);
		 
		aq.id(R.id.tvtitle).text(u.getTitle());
		aq.id(R.id.tvcontent).text(u.getContent());
		aq.id(R.id.tvpublishUser).text(u.getPublishUser());
		aq.id(R.id.tvtime).text(u.getPubshTime());
		aq.id(R.id.img).image(u.getImg(),true,true);
		return convertView;
	}
}
